#ifndef __LAMPE__VECTOR3D_H__
#define __LAMPE__VECTOR3D_H__

#include <lampe/base_type_vendor.h>
#include <lampe/stream/Serializable.h>

namespace lampe{
namespace core{

template <typename T>
class vector2d:public stream::Serializable{
public:
    T X;
    T Y;
    vector2d():X(0),Y(0){}
    vector2d(T x,T y):X(x),Y(y){}

    f32 lengthSQ(){
        return X*X+Y*Y;
    }

    f32 length(){
        return sqrt(lengthSQ());
    }
    vector2d<T> normalize(){
        if (X==0 && Y==0)
            return *this;

        f64 length=1/length();

        X=(T)(X*length);
        Y=(T)(Y*length);
        return*this;
    }

	virtual void serialization(stream::IWriter*stream){
		stream->write(&X,sizeof(T));
		stream->write(&Y,sizeof(T));
	}

	virtual void deserialization(stream::IReader*stream){
		stream->read(&X,sizeof(T));
		stream->read(&Y,sizeof(T));
	}
};

typedef vector2d<u32> Vector2u;
typedef vector2d<s32> Vector2i;
typedef vector2d<f32> Vector2f;

}//namespace core
}//namespace lampe


#endif
